'use strict'

var initdb=require('./initDb');

initdb();

var table=require('./uitle/table');

var Crawler=require('crawler');

 

var c=new Crawler({
    maxConnections:10,
    callback:function(error,res,done){
        if(error){
            Console.log(error);
        }else{
            var $=res.$;
            var list=$('.dw_table .el').toArray();
            list.forEach(element => {
                var text1=$(element).find('.t1 a').attr('title');
                var text2=$(element).find('.t2 a').text().trim().replace(/[\n\r]/g,"");
                var text3=$(element).find('.t3').text().trim().replace(/[\n\r]/g,"");
                var text4=$(element).find('.t4').text().trim().replace(/[\n\r]/g,"");
                var text5=$(element).find('.t5').text().trim().replace(/[\n\r]/g,"");

                // Console.log(text1);
                // Console.log(text2);
                // Console.log(text3);
                // Console.log(text4);
                // Console.log(text5);
                table.create({Vocat:text1,Company:text2,Site:text3,Pay:text4,Datetime:text5})
            });
        }
        done();
    }
});
for(let index=1;index<=9;index++){
    c.queue('https://search.51job.com/list/010000%252C180200%252C020000%252C030200%252C040000,000000,7501,00,9,99,%2520,1,'+index+'.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare=');
}